package com.guoguo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.guoguo.base.BaseController;
import com.guoguo.entity.Statistical;
import com.guoguo.entity.SysImg;
import com.guoguo.entity.vo.RankingVO;
import com.guoguo.service.IStatisticalService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/26 0026.
 */
@Controller
@RequestMapping("/view")
public class StatisticalController extends BaseController {
    @Resource
    private IStatisticalService iStatisticalService;


    /**
     * 查询全部的排行数据
     * @param type1
     * @param type2
     * @param type3
     * @return
     */
        @RequestMapping(value = "/top",method = RequestMethod.GET)
        public ModelAndView bang(Integer type1,Integer type2,Integer type3 ){
            Map<String, Object> data = new HashedMap();
            List<RankingVO> rankingVOs1 = iStatisticalService.getRanking(type1);
            List<RankingVO> rankingVOs2 = iStatisticalService.getRanking(type2);
            List<RankingVO> rankingVOs3 = iStatisticalService.getRanking(type3);
            data.put("rankingVOs1",rankingVOs1);
            data.put("rankingVOs2",rankingVOs2);
            data.put("rankingVOs3",rankingVOs3);
            return returnView("/statistical",data);
        }

    /**
     * 根据type去查询
     * @param type
     * @return
     */

    @RequestMapping(value ="/getStatistical",method = RequestMethod.GET )
    public ModelAndView  getStatisticalList( Integer type){
        Map<String, Object> data = new HashedMap();
        if(type==1){
            List<RankingVO> rankingVOs1 = iStatisticalService.getRanking(type);
            data.put("rankingVOs1",rankingVOs1);
        }else if (type==2){
            List<RankingVO> rankingVOs2 = iStatisticalService.getRanking(type);
            data.put("rankingVOs2",rankingVOs2);
        }else{
            List<RankingVO> rankingVOs3 = iStatisticalService.getRanking(type);
            data.put("rankingVOs3",rankingVOs3);
        }
        return returnView("/statistical", data);
    }

    /**
     * 去跳转修改排行
     * @param albId
     * @param type
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/toUpdate",method = RequestMethod.GET )
    public ModelAndView toUpdate(String albId,Integer type){
        Map<String, Object> data = new HashedMap();
         RankingVO rankingVO = iStatisticalService.selectByIdType(albId, type);
            data.put("rankingVO",rankingVO);
        return returnView("/statistical/statisticalUpdate", data);
    }

    @ResponseBody
    @RequestMapping(value = "/updateStatistical",method = RequestMethod.GET)
        public JSONObject update(Statistical statistical){
        Map<String, Object> data = new HashedMap();
        iStatisticalService.updateByIdType(statistical);
        return returnResult(200, data, "");
    }

}
